package udp;

public class UdpChecksum {

    static long checksum(int[] data) {
//ab:cd:ef:ff:00:00:00:01:00:00:00:00:00:00:00:00:00:00:00:24:63:6f:6d:2e:6d:75:6c:74:69:73:63:72:65:65:6e:2e:66:72:61:6d:65:77:6f:72:6b:2e:73:65:6e:64:2e:69:73:62:6f:78:00:00:00:26:63:6f:6d:2e:6d:75:6c:74:69:73:63:72:65:65:6e:2e:66:72:61:6d:65:77:6f:72:6b:2e:72:65:63:65:69:76:65:72:2e:61:70:70:00:00:00:10:00:00:00:02:00:00:00:08:39:30:36:37:33:35:32:34:ff:fe:dc:ba
        long sum = 0;

        for (int i = 0; i < data.length; i++) {

            sum += data[i];

            sum = (sum >> 16) + (sum & 0xFFFF);
        }

        return ~sum;

    }

    public static void main(String[] args) {

        System.out.println(0xdfd1);

        int[] data = new int[]{0x0aaa, 0x3bbf, 0xd20e, 0x960d, 0x0011, 0x001c, 0xd123, 0x2742, 0x001c, 0x0000, 0x6c41, 0x5661, 0x0000, 0x0e00, 0xf8b6, 0xd401, 0x9313, 0x0000, 0x0000, 0x0000};

        System.out.println(Long.toBinaryString(checksum(data)));
    }


}
